package yogiro.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import yogiro.to.NoticeCommentTO;
import yogiro.to.NoticeTO;

public class NoticeDAO {
private SqlMapClientTemplate sqlMap;
	
	public NoticeDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	
	public int seqNo()throws SQLException{
		return (int)sqlMap.queryForObject("seqNo");
	}
	public void insertNotice(NoticeTO nto)throws SQLException{
		System.out.println(nto);
		sqlMap.insert("insertNotice",nto);
	}

	public void updateViewCount(int no) throws SQLException{
		sqlMap.update("updateNoticeViewCount",no);
	}
	public NoticeTO selectContentByNO(int no) throws SQLException{
		return (NoticeTO)sqlMap.queryForObject("selectContentByNO",no);
	}
	public void updateContent(NoticeTO nto) throws SQLException{
		 sqlMap.update("updateNoticeContent",nto);
	}
	public void deleteContentByNO(int no) throws SQLException{
		sqlMap.delete("deleteContentByNO",no);
	}
	//paging 목록
	public ArrayList<NoticeTO> selectNoticeAllList(HashMap map) throws SQLException{
		System.out.println(map);
		return (ArrayList<NoticeTO>)sqlMap.queryForList("selectNoticeAllList",map);
	}
	public ArrayList<NoticeTO> selectNoticeAllList1(HashMap map) throws SQLException{
		System.out.println(map);
		return (ArrayList<NoticeTO>)sqlMap.queryForList("selectNoticeAllList1",map);
	}
	public ArrayList<NoticeTO> selectNoticeAllList2(HashMap map) throws SQLException{
		System.out.println(map);
		return (ArrayList<NoticeTO>)sqlMap.queryForList("selectNoticeAllList2",map);
	}
	//총 게시물 수를 return 하는 메소드 
	public int selectTotalContent() throws SQLException{
		return (Integer)sqlMap.queryForObject("selectTotalNoticeContent");
	}
	public int byWriterCount() throws SQLException{
		return (Integer)sqlMap.queryForObject("byWriterCount");
	}
	public int byTitleCount() throws SQLException{
		return (Integer)sqlMap.queryForObject("byTitleCount");
	}
	//삭제 메소드
	public Object deleteComment(int commentNo,int noticeNo)throws SQLException{
		HashMap map = new HashMap();
		map.put("commentNo", commentNo);
		map.put("noticeNo", noticeNo);
		return sqlMap.delete("deleteNoticeComment",map);
	}
	
	//no로 조회
	public NoticeCommentTO selectByNo(int commentNo)throws SQLException{
		return (NoticeCommentTO)sqlMap.queryForList("selectByNo",commentNo);
	}
	
	public ArrayList<NoticeCommentTO> selectCommentByNO(int notice_No)throws SQLException{
		System.out.println("다오에서");
		System.out.println((ArrayList<NoticeCommentTO>) sqlMap.queryForList("selectCommentByNO",notice_No));
		return (ArrayList<NoticeCommentTO>) sqlMap.queryForList("selectCommentByNO",notice_No);
	}
	public ArrayList<NoticeTO> selectByTitle(String title)throws SQLException{
		return (ArrayList<NoticeTO>)sqlMap.queryForList("selectByTitle",title);
	}
	public ArrayList<NoticeTO> selectByWriter(String writer)throws SQLException{
		return (ArrayList<NoticeTO>)sqlMap.queryForList("selectByWriter",writer);
	}
	public int selectCommentCount(int noticeNo)throws SQLException{
		return (Integer)sqlMap.queryForObject("selectCommentCount", noticeNo);
	}
	//넘버찾기
	public int byNextNO(int notice_no)throws SQLException{
		return (Integer)sqlMap.queryForObject("byNextNO",notice_no);
	}
	public int byMax()throws SQLException{
		return (Integer)sqlMap.queryForObject("byMax");
	}
	public int byPreNO(int notice_no)throws SQLException{
		return (Integer)sqlMap.queryForObject("byPreNO",notice_no);
	}
	public int byMin()throws SQLException{
		return (Integer)sqlMap.queryForObject("byMin");
	}
	public ArrayList<NoticeTO>  selectNoticeDate(HashMap map)throws SQLException{
		return (ArrayList<NoticeTO>)sqlMap.queryForList("selectNoticeDate",map);
	}
	public int byDate(HashMap map1)throws SQLException{
		return (Integer)sqlMap.queryForObject("byDate", map1);
	}
}
